﻿using System;
using System.Collections.Generic;
using System.Linq;
using FlashCards.Model;
using System.Drawing;
using System.IO;
using System.ComponentModel.DataAnnotations;

namespace FlashCards.WebApp.Models
{
    public class UserModel
    {
        public UserModel(User user)
        {
            Id = user.UserId;
            Nick = user.Nick;
            Name = user.Name;
            Surname = user.Surname;
            BirthDate = user.BirthDate.HasValue ? user.BirthDate.Value.ToString("yyyy-MM-dd") : string.Empty;

            if (user.MembershipReference.IsLoaded)
                LastLoginDate = user.Membership.LastLoginDate.HasValue ? user.Membership.LastLoginDate.Value : DateTime.MinValue;
        }

        public UserModel() { }

        public int Id { get; set; }

        [Required]
        [MinLength(2)]
        [MaxLength(20)]
        public string Nick { get; set; }

        [Required]
        [MinLength(3)]
        [MaxLength(20)]
        [RegularExpression("^\\p{Lu}\\p{Ll}+$", ErrorMessage = "Pierwsza drukowana litera, kolejne małe")]
        public string Name { get; set; }

        [MinLength(3)]
        [MaxLength(20)]
        public string Surname { get; set; }

        public DateTime LastActivityDate { get; set; }
        public DateTime LastLoginDate { get; set; }
        public int Age { get; set; }

        [RegularExpression("^(19|20)\\d\\d[/-](0[1-9]|1[012])[/-](0[1-9]|[12][0-9]|3[01])$", ErrorMessage = "format - yyyy/mm/dd")]
        public string BirthDate { get; set; }

        //dodane bez modyfikacji w diagramie

        public string Password { get; set; }
        public string Email { get; set; }
    }
}